﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class Complaint
    {
        public static int insert(ComplaintEntity clEnt)
        {
            return Convert.ToInt32(DbHelper.ExecuteScalar("[dbo].[p_Complaint_insert]", clEnt.BuyerId,clEnt.ComplaintDt,clEnt.ProductId,clEnt.ComplaintType,
                clEnt.DepartmentId,clEnt.DepartmentItemId,clEnt.ResponsibleId,clEnt.SellerId,clEnt.ComplaintLevel,clEnt.ComplaintResult,clEnt.Remarks,clEnt.adminId));
        }

        public static void update(ComplaintEntity clEnt)
        {
            DbHelper.ExecuteNonQuery("[dbo].[p_Complaint_update]", clEnt.ComplaintId, clEnt.ComplaintDt, clEnt.BuyerId, clEnt.ProductId, clEnt.ComplaintType, clEnt.DepartmentId, clEnt.DepartmentItemId, clEnt.ResponsibleId, clEnt.SellerId, clEnt.ComplaintLevel, clEnt.ComplaintResult, clEnt.Remarks,clEnt.adminId);
        }
        public static DataSet OutputExcel(string where)
        {
            return DbHelper.ExecuteReDataSet("p_Complaint_listByExcel", where);
        }
        public static ComplaintEntity getBycId(int cId)
        {
            DataRow dr = DbHelper.ExecuteDataRow("[dbo].[p_Complaint_getById]", cId);
            ComplaintEntity clEnt = new ComplaintEntity();
            if (dr != null)
            {
                clEnt.ComplaintId = cId;
                if (dr["ComplaintDt"] != DBNull.Value)
                    clEnt.ComplaintDt = Convert.ToDateTime(dr["ComplaintDt"]);
                if (dr["buyerid"] != DBNull.Value)
                    clEnt.BuyerId = Convert.ToInt32(dr["buyerid"]);
                if (dr["productId"] != DBNull.Value)
                    clEnt.ProductId = Convert.ToInt32(dr["productId"]);
                if (dr["ComplaintType"] != DBNull.Value)
                    clEnt.ComplaintType = Convert.ToInt32(dr["ComplaintType"]);
                if (dr["DepartmentId"] != DBNull.Value)
                    clEnt.DepartmentId = Convert.ToInt32(dr["DepartmentId"]);
                if (dr["DepartmentItemId"] != DBNull.Value)
                    clEnt.DepartmentItemId = Convert.ToInt32(dr["DepartmentItemId"]);
                if (dr["ResponsibleId"] != DBNull.Value)
                    clEnt.ResponsibleId = Convert.ToInt32(dr["responsibleid"]);
                if (dr["SellerId"] != DBNull.Value)
                    clEnt.SellerId = Convert.ToInt32(dr["SellerId"]);
                if (dr["ComplaintLevel"] != DBNull.Value)
                    clEnt.ComplaintLevel = Convert.ToInt32(dr["ComplaintLevel"]);
                clEnt.ComplaintResult = dr["ComplaintResult"].ToString();
                clEnt.Remarks = dr["Remarks"].ToString();
                if (dr["InputDt"] != DBNull.Value)
                    clEnt.InputDt = Convert.ToDateTime(dr["InputDt"]);
                if (dr["adminid"] != DBNull.Value)
                    clEnt.adminId = Convert.ToInt32(dr["adminid"]);
            }
            return clEnt;
        }
    }
}
